<?php
/**
 *APINAME:
 *Developer:
 *Complete:
 */

namespace app\index\common;


use think\Controller;
use think\facade\Cache;
use think\facade\Request;

class BaseController extends Controller
{
    //自定义http状态码
    const OK = 200;                         //请求成功
    const ERROR = 4000;               //请求失败
    const LOGON = 4001;               //未登录
    const TICKET = 4002;               //票数不够

    //定义返回信息
    public function returnJson($code,$message,$data = null){
        $back = [
            'code'          =>          $code,
            'message'   =>          $message,
            'data'          =>           $data
        ];
        return json($back);
    }

    public function getUserId(){
        $token = Request::header('Authorization');
        return Cache::get($token)['id'];
    }
}